package com.hy.service.impl;

import com.hy.bean.PurchaseApplyDetail;
import com.hy.bean.RespBean;
import com.hy.dao.PurchaseApplyDetailDao;
import com.hy.dao.impl.PurchaseApplyDetailDaoImpl;
import com.hy.service.PurchaseApplyDetailService;
import org.springframework.stereotype.Service;

/**
 * (PurchaseApplyDetail)表服务实现类
 *
 * @author makejava
 * @since 2024-04-29 14:47:14
 */
@Service("purchaseApplyDetailService")
public class PurchaseApplyDetailServiceImpl implements PurchaseApplyDetailService {

    private PurchaseApplyDetailDao purchaseApplyDetailDao = new PurchaseApplyDetailDaoImpl();

    /**
     * 通过ID查询单条数据
     *
     * @param id
     * @return 实例对象
     */
    @Override
    public PurchaseApplyDetail queryById(int id) {
        return this.purchaseApplyDetailDao.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param purchaseApplyDetail 实例对象
     * @return 实例对象
     */
    @Override
    public RespBean insert(PurchaseApplyDetail purchaseApplyDetail) {
        /*List<Integer> insert = new ArrayList<>();
        if (purchaseApplyDetail.getGoodsId().length() > 0) {
            String[] goodsId = purchaseApplyDetail.getGoodsId().split(",");
            for (int i = 0; i < goodsId.length; i++) {
                purchaseApplyDetail.setGoodsId(goodsId[i]);
                insert.add(purchaseApplyDetailDao.insert(purchaseApplyDetail));
            }
        }*/
        int insert = purchaseApplyDetailDao.insert(purchaseApplyDetail);
        if (insert > 0) {
            return new RespBean().success("添加成功");
        }
        return new RespBean().error("添加失败");
    }

    /**
     * 修改数据
     *
     * @param purchaseApplyDetail 实例对象
     * @return 实例对象
     */
    @Override
    public RespBean update(PurchaseApplyDetail purchaseApplyDetail) {
        int update = purchaseApplyDetailDao.update(purchaseApplyDetail);
        if (update > 0) {
            return new RespBean().success("修改成功");
        }
        return new RespBean().error("修改失败");
    }

    /**
     * 通过主键删除数据
     *
     * @param id
     * @return 是否成功
     */
    @Override
    public RespBean deleteById(Integer id) {
        if (purchaseApplyDetailDao.deleteById(id) > 0) {
            return new RespBean().success("删除成功");
        }
        return new RespBean().error("删除失败");
    }
}
